package menu

import (
	"context"
	"fast-boot/app/api/admin/internal/svc"
	"fast-boot/app/api/admin/internal/types"
	"fast-boot/app/model"
	"github.com/hwUltra/fb-tools/gormx"
	"github.com/hwUltra/fb-tools/jwtx"

	"github.com/zeromicro/go-zero/core/logx"
)

type RoutesLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRoutesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoutesLogic {
	return &RoutesLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RoutesLogic) Routes() (resp []*types.RouteData, err error) {
	userId := jwtx.NewJwtX(l.ctx, l.svcCtx.Config.JwtUserKey).GetUid()
	items := (*model.SysMenuCache)(gormx.NewCacheTool(l.svcCtx.Config.Cache, l.svcCtx.GormClient.GormDb)).Routes(userId)
	return GetRoutes(items, 0), nil
}
